package com.lyloou.practice.service;


import com.lyloou.practice.annotation.Autowired;
import com.lyloou.practice.annotation.Qualifier;
import com.lyloou.practice.annotation.Service;
import com.lyloou.practice.annotation.Transactional;
import com.lyloou.practice.dao.AccountDao;
import com.lyloou.practice.pojo.Account;
import com.lyloou.practice.utils.TransactionManager;

/**
 * @author 应癫
 */
@Service("transferServiceWithoutService")
public class TransferServiceWithoutService {


    @Autowired
    private AccountDao accountDao;

    @Autowired
    @Qualifier("transactionManager")
    TransactionManager transactionManager;


    @Transactional
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
        Account fromAccount = accountDao.queryAccountByCardNo(fromCardNo);

        Account toAccount = accountDao.queryAccountByCardNo(toCardNo);
        fromAccount.setMoney(fromAccount.getMoney() - money);
        toAccount.setMoney(toAccount.getMoney() + money);
        accountDao.updateAccountByCardNo(fromAccount);
//        int c = 1 / 0;
        accountDao.updateAccountByCardNo(toAccount);
    }
}
